package com.cwm.test.composite.demo.safe;

import com.cwm.test.composite.demo.transparent.CourseComponent;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class Folder extends Directory {

    private List<Directory> dirs;

    private Integer level;

    public Folder(String name, Integer level) {
        super(name);
        this.level = level;
        this.dirs = new CopyOnWriteArrayList<>();
    }

    @Override
    public void show() {

        System.out.println(this.name);

        for (Directory cc : dirs) {
            if (this.level != null) {
                for (int i = 0; i < this.level; i++) {
                    System.out.print("  ");
                }
                for (int i = 0; i < this.level; i++) {
                    if (i == 0) {
                        System.out.print("+");
                    }
                    System.out.print("-");
                }
            }
            cc.show();
        }
    }

    public boolean add(Directory directory) {
        return this.dirs.add(directory);
    }

    public boolean remove(Directory directory) {
        return this.dirs.remove(directory);
    }

    public void list() {
        for (Directory c : dirs) {
            System.out.println(c.name);
        }
    }

}
